//translate.js

var util = require('../../utils/util.js')
var app = getApp()
const domainUrl = app.globalData.domainUrl
// const domainUrl = "http://localhost:8771/"

Page({
  data: {
    duration: 2000,
    indicatorDots: true,
    autoplay: true,
    interval: 3000,
    loading: false,
    plain: false,
    userInfo: {},
    currentID: '0',
    menuItems: [
      {
        courseName: '卡片排行榜',
        id: '0'
      },
      {
        courseName: '等级排行榜',
        id: '1'
      }
    ],
  },
  onLoad: function (params) {
    util.login(this.route);
    var that = this
    wx.request({
      url: domainUrl + 'rankingBoard',
      success: function (res) {
        console.log(res.data);
        that.setData({
          dataList: res.data.data
        })
      }
    })
  },
  tapMenuItem: function (e) {
    var that = this;
    console.log(e.currentTarget.id);
    var id = e.currentTarget.id;

    var url;
    if(id == '0') {
      url = domainUrl + 'rankingBoard';
    } else {
      url = domainUrl + 'levelRankingBoard';
    }
    wx.request({
      url: url,
      success: function (res) {
        console.log(res.data);
        that.setData({
          dataList: res.data.data,
          currentID: e.currentTarget.id
        })
      }
    })
  },
  onReady: function () {
    wx.setNavigationBarTitle({ title: '排行榜', success: function (res) { } });
    this.innerAudioContext = wx.createInnerAudioContext();
  },
  onShow: function () {
    console.log("显示图片")
    var that = this;
    that.setData({
      currentID: '0'
    })
    var openid = wx.getStorageSync('my_openid');
    this.onLoad();  
  },

  translateText: function (e) { this.setData({ translateValue: e.detail.value }) },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: '水浒卡',
      path: '/pages/card/card',
      success: function (res) { },
      fail: function (res) { }
    }
  }
})